package com.zmm.zebulon.module.pay.controller.admin.transfer;

import com.zmm.zebulon.common.pojo.CommonResult;
import com.zmm.zebulon.common.pojo.PageResult;
import com.zmm.zebulon.module.pay.controller.admin.transfer.vo.PayTransferPageItemRespVO;
import com.zmm.zebulon.module.pay.controller.admin.transfer.vo.PayTransferPageReqVO;
import com.zmm.zebulon.module.pay.controller.admin.transfer.vo.PayTransferRespVO;
import com.zmm.zebulon.module.pay.convert.transfer.PayTransferConvert;
import com.zmm.zebulon.module.pay.dal.dataobject.transfer.PayTransferDO;
import com.zmm.zebulon.module.pay.service.transfer.PayTransferService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * description: 管理后台 - 转账单
 *
 * @author zebulon
 * package com.zmm.zebulon.module.pay.controller.transfer
 * name: PayTransferController
 * date 2024/1/11 23:51
 */
@Tag(name = "管理后台 - 转账单")
@RestController
@RequestMapping("/pay/transfer")
@Validated
public class PayTransferController {

    @Resource
    private PayTransferService payTransferService;

    /**
    @PostMapping("/create")
    @Operation(summary = "创建转账单，发起转账")
    @PreAuthorize("@ss.hasPermission('pay:transfer:create')")
    public CommonResult<PayTransferCreateRespVO> createPayTransfer(@Valid @RequestBody PayTransferCreateReqVO reqVO) {
        PayTransferDO payTransfer = payTransferService.createTransfer(reqVO, getClientIP());
        return CommonResult.success(new PayTransferCreateRespVO().setId(payTransfer.getId()).setStatus(payTransfer.getStatus()));
    }
     */

    @GetMapping("/get")
    @Operation(summary = "获得转账订单")
    @PreAuthorize("@ss.hasPermission('pay:transfer:query')")
    public CommonResult<PayTransferRespVO> getTransfer(@RequestParam("id") Long id) {
        return CommonResult.success(PayTransferConvert.INSTANCE.convert(payTransferService.getTransfer(id)));
    }

    @GetMapping("/page")
    @Operation(summary = "获得转账订单分页")
    @PreAuthorize("@ss.hasPermission('pay:transfer:query')")
    public CommonResult<PageResult<PayTransferPageItemRespVO>> getTransferPage(@Valid PayTransferPageReqVO pageVO) {
        PageResult<PayTransferDO> pageResult = payTransferService.getTransferPage(pageVO);
        return CommonResult.success(PayTransferConvert.INSTANCE.convertPage(pageResult));
    }
}
